﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace App
{
    public partial class Registration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            //potreba kvuli customvalidatoru, validace je serverside, zastavi se odsilani a validator se vypise, protoze neni polozka v poradku
            if (Page.IsValid == false)
                return;

            if (MidApp.ManageUser.UserAlreadyExists(txtboxNick.Text))
            {
                lblInfo.Text = "Tuto přezdívku nelze použít, jelikož je již obsazena";
                Panel2.Visible = true;
            }
            else
            {
                AppLib.User newUser = new AppLib.User();    
               
                    newUser.Nick = txtboxNick.Text;
                    newUser.Name = txtname.Text;
                    newUser.Surname = txtsurname.Text;
                    newUser.Address = txtAddress.Text;
                    newUser.PhoneNumber = txtPhone.Text;
                    newUser.PrimaryEmail = txtEmailP.Text;
                    newUser.SecondaryEmail = txtEmailS.Text;
                    newUser.ICQNumber = txtICQ.Text;
                    newUser.Active = true;
                    newUser.ImageURL = TextBoxURL.Text;

                MidApp.ManageUser.CreateNewUser(newUser,txtboxPassword.Text);


                Response.Cookies["registeredUser"].Value = Server.UrlEncode("Registrace proběhla úspěšně");
                Response.Redirect("Login.aspx");
            }            
        }
    }
}